package com.chance.cc.crawler.development.bootstrap.mogu;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import org.junit.Test;

import java.net.URLEncoder;
import java.util.UUID;

/**
 * @ClassName mogujie
 * @Description TODO
 * @Author songding
 * @Date 2021/10/15 9:41
 * @Version 1.0
 * 蘑菇街关键字采集
 **/
public class moguStart {
    private static final String domain = "mogu";
    private static final String site = "article";

    private static Proxy proxy = new Proxy();
    static {
        //代理配置
        //HL89Q19E86E2987D
        //71F33D94CE5F7BF2
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("HL89Q19E86E2987D");
        proxy.setPassword("71F33D94CE5F7BF2");
    }
    public static void main(String[] args) {
        gatherSeries();
    }
    public static void gatherSeries() {
        String url = "https://list.mogu.com/search/goods?q=%E8%A3%99%E5%AD%90";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .httpUrl(url)
                .domain(domain)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24 * 10000, null))
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .proxy(proxy)
                .build();
        record.setNeedWashPage(false);
        record.setNeedParsedPage(false);
        record.tagsCreator().bizTags().addSite(site);
        record.tagsCreator().bizTags().addSiteBiz(site);
        record.tagsCreator().bizTags().addDomain(domain);
        ///record.tagsCreator().bizTags().addCustomKV("q","%E8%A3%99%E5%AD%90");
        record.setDownload(false);
        record.setSkipPipeline(true);
        CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPageItem)
                .httpUrl("http://192.168.1.217:9599/v1/meta/mogu/keys?site=searchKw")
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.supportSource)
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.internalDownload)
                .build();


        DevCrawlerController.builder()
                .triggerInfo(domain, domain, System.currentTimeMillis(), domain)
                .crawlerThreadNum(1)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline()
                .requestRecord(record)
                .supportRecord(keywordRecord)
                .build("com.chance.cc.crawler.development.scripts.mogu")
                .start();
    }
    @Test
    public void test(){
        System.out.println(UUID.randomUUID().toString());
        String s =URLEncoder.encode("{\"page\":1,\"pageSize\":24,\"sort\":\"pop\",\"ratio\":\"3:4\",\"cKey\":\"pc-search-wall\",\"q\":\""+"裙子"+"\",\"ptp\":\"31.DGODi.0.0.2sT0NnmK\"}");
        System.out.println(s);
        System.out.println(System.currentTimeMillis());
    }
}
